const constant = require("../../util/constant.js");
const util = require('../../util/util.js');
const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    index: 0,
    switchck:true,
    aypicker: [],
    aypickname:[],
    emps:[],
    empnames:[],
    imgList: [],
    imgurls:[],
    modalName: null,
    dsrtitle:'当事人姓名',
    dsrhmtitle:'身份证号',
    smhide:false,
    address:'',
    hourMinuteSecond: '',//时分，案发时间
    timeDivision: '',//时分秒，根据需要选择
    isperson:1,
    dsrname:'',
    dsrhm:'',
    dsrzhuzhi:'',
    dsrtel:'',
    afaddress:'',
    date: '',//责令改正日期
    jkdate:'',//交款时间
    daxie:'',//交款金额大写
    fkxx:'',//小写
    fkpjh:'',//罚款票据号
    khyh:constant.bankname,
    khyhzh:constant.bankno,
    zbr:'',
    zbrid:'',
    zbrbh:'',
    xbindex:0,
    xbr:'',
    xbrid:'',
    ayName:'',
    ayid:'',
    jzimg:'',
    zxbm:'',
    gzstat:0,
    cfstat:0,
    fkstat:0,
    ajid:0,
    zlck1:true,
    zlck2:false,
    cfck1:true,
    cfck2:false,
    fkck1:true,
    fkck2:false,
    ajstat:0,
    jkhide:true,
    imgpath:constant.host+"/content/jyjzimg/"+constant.cityid+"/",
    cardtype:'idCard',
    saomiaohd:false
  },
  gzqkchenge:function(e){
      let st=e.detail.value;
      //console.log(st);
    this.setData({
        gzstat:st
    })
  },
  cfqkchenge:function(e){
    let st=e.detail.value;
    var cfxx=this.data.fkxx;
    let jkhd=true;
    if(st==0)
    {
        cfxx=0;
    }
    else
    {
        jkhd=false;
    }
    //console.log(st);
  this.setData({
      cfstat:st,
      jkhide:jkhd,
      fkxx:cfxx
  })
},
fkqkchenge:function(e){
    let st=e.detail.value;
    //console.log(st);
  this.setData({
      fkstat:st
  })
},
  changeToChineseMoney(Num) {
    //判断如果传递进来的不是字符的话转换为字符
    if (typeof Num == "number") {
        Num = new String(Num);
    };
    Num = Num.replace(/,/g, "") //替换tomoney()中的“,”
    Num = Num.replace(/ /g, "") //替换tomoney()中的空格
    Num = Num.replace(/￥/g, "") //替换掉可能出现的￥字符
    if (isNaN(Num)) { //验证输入的字符是否为数字
        //alert("请检查小写金额是否正确");
        return "";
    };
    //字符处理完毕后开始转换，采用前后两部分分别转换
    var part = String(Num).split(".");
    var newchar = "";
    //小数点前进行转化
    for (var i = part[0].length - 1; i >= 0; i--) {
        if (part[0].length > 10) {
            return "";
            //若数量超过拾亿单位，提示
        }
        var tmpnewchar = ""
        var perchar = part[0].charAt(i);
        switch (perchar) {
            case "0":
                tmpnewchar = "零" + tmpnewchar;
                break;
            case "1":
                tmpnewchar = "壹" + tmpnewchar;
                break;
            case "2":
                tmpnewchar = "贰" + tmpnewchar;
                break;
            case "3":
                tmpnewchar = "叁" + tmpnewchar;
                break;
            case "4":
                tmpnewchar = "肆" + tmpnewchar;
                break;
            case "5":
                tmpnewchar = "伍" + tmpnewchar;
                break;
            case "6":
                tmpnewchar = "陆" + tmpnewchar;
                break;
            case "7":
                tmpnewchar = "柒" + tmpnewchar;
                break;
            case "8":
                tmpnewchar = "捌" + tmpnewchar;
                break;
            case "9":
                tmpnewchar = "玖" + tmpnewchar;
                break;
        }
        switch (part[0].length - i - 1) {
            case 0:
                tmpnewchar = tmpnewchar + "元";
                break;
            case 1:
                if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
                break;
            case 2:
                if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
                break;
            case 3:
                if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
                break;
            case 4:
                tmpnewchar = tmpnewchar + "万";
                break;
            case 5:
                if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
                break;
            case 6:
                if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
                break;
            case 7:
                if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
                break;
            case 8:
                tmpnewchar = tmpnewchar + "亿";
                break;
            case 9:
                tmpnewchar = tmpnewchar + "拾";
                break;
        }
        var newchar = tmpnewchar + newchar;
    }
    //小数点之后进行转化
    if (Num.indexOf(".") != -1) {
        if (part[1].length > 2) {
            // alert("小数点之后只能保留两位,系统将自动截断");
            part[1] = part[1].substr(0, 2)
        }
        for (i = 0; i < part[1].length; i++) {
            tmpnewchar = ""
            perchar = part[1].charAt(i)
            switch (perchar) {
                case "0":
                    tmpnewchar = "零" + tmpnewchar;
                    break;
                case "1":
                    tmpnewchar = "壹" + tmpnewchar;
                    break;
                case "2":
                    tmpnewchar = "贰" + tmpnewchar;
                    break;
                case "3":
                    tmpnewchar = "叁" + tmpnewchar;
                    break;
                case "4":
                    tmpnewchar = "肆" + tmpnewchar;
                    break;
                case "5":
                    tmpnewchar = "伍" + tmpnewchar;
                    break;
                case "6":
                    tmpnewchar = "陆" + tmpnewchar;
                    break;
                case "7":
                    tmpnewchar = "柒" + tmpnewchar;
                    break;
                case "8":
                    tmpnewchar = "捌" + tmpnewchar;
                    break;
                case "9":
                    tmpnewchar = "玖" + tmpnewchar;
                    break;
            }
            if (i == 0) tmpnewchar = tmpnewchar + "角";
            if (i == 1) tmpnewchar = tmpnewchar + "分";
            newchar = newchar + tmpnewchar;
        }
    }
    //替换所有无用汉字
    while (newchar.search("零零") != -1)
        newchar = newchar.replace("零零", "零");
    newchar = newchar.replace("零亿", "亿");
    newchar = newchar.replace("亿万", "亿");
    newchar = newchar.replace("零万", "万");
    newchar = newchar.replace("零元", "元");
    newchar = newchar.replace("零角", "");
    newchar = newchar.replace("零分", "");
    if (newchar.charAt(newchar.length - 1) == "元") {
        newchar = newchar + "整"
    }
    return newchar;
},
getdaxie:function(e)
{
    var xx=e.detail.value.fkxx;
    //console.log(xx);
},
  selectDateMinuteChange(e) {
    this.setData({
      hourMinuteSecond: e.detail.value
    })
  },
  // 时分秒的事件方法
  selectDateSecondChange(e) {
    this.setData({
      timeDivision: e.detail.value
    })
  },
  idcardsuccess:function(res){
    let isp=this.data.isperson;
    let dsrnmae='';
    let dsrcardno='';
    let addr='';
    if(isp>0)
    {
        dsrnmae=res.detail.name.text;
        dsrcardno=res.detail.id.text;
        addr=res.detail.address.text;
    }
    else
    {
        console.log(res.detail);
        dsrnmae=res.detail.enterprise_name.text;
        dsrcardno=res.detail.reg_num.text;
        addr=res.detail.address.text;
    }
    this.setData({
        dsrname:dsrnmae,
        dsrhm:dsrcardno,
        dsrzhuzhi:addr
    })
  },
  onLoad:function(option){
    var myuid=wx.getStorageSync('userid');
    
    //console.log(myuid);
    if(myuid!='')
    {  
        this.setData({
            khyh:wx.getStorageSync('cbank'),
            khyhzh:wx.getStorageSync('bankno')
        })
    }
    else
    {
        wx.redirectTo({
          url: '../login/index',
        })
    }
    var ajzbr=wx.getStorageSync('uname');
    var zbid=wx.getStorageSync('userid');
    var zbbh=wx.getStorageSync('uzfzbh');
    var bm=wx.getStorageSync('udept');
    var myid=0;
    if(option.iscopy!=null)
    {
        if(option.iscopy==1)
        {
            let cdsr=option.dsr;
            let cdsrhm=option.dsrhm;
            let cdsrtel=option.dsrtel;
            let cdsraddr=option.dsraddr;
            let cisp=option.isp;
            let cpsck=true;
                let cdsrhmt="";
                if(cisp>0)
                {
                    cpsck=true;
                    cdsrhmt="身份证号";
                }
                else
                {
                    cpsck=false;
                    cdsrhmt="统一社会信用代码";
                }
                this.setData({
                    switchck:cpsck,
                    isperson:cisp,
                    dsrname:cdsr,
                    dsrhm:cdsrhm,
                    dsrzhuzhi:cdsraddr,
                    dsrtel:cdsrtel,
                    dsrhmtitle:cdsrhmt,
                    saomiaohd:true
                })
        }
    }
    if(option.id!=null && option.id!="")
    {
        myid=option.id;
    }
    //console.log(myid);
    this.setData({
        zbr:ajzbr,
        zbrbh:zbbh,
        zbrid:zbid,
        ajid:myid,
        zxbm:bm
    })
    var ayid=0;
    if(myid>0)
    {
        var that=this;
      wx.request({
          url: constant.host+'/appserv/getjz.ashx',
          data: {
            aid:myid,
            k: constant.wkey
          },
          success: function (data) {
              
            var dat = data.data;
            if(dat.length>0)
            {
                var mydata=dat[0];
                let isp=mydata.IsPerson;
                //console.log(myid+'|'+isp);
                let psck=true;
                let dsrhm="";
                if(isp>0)
                {
                    psck=true;
                    dsrhm="身份证号";
                }
                else
                {
                    psck=false;
                    dsrhm="统一社会信用代码";
                }
                let zlgzst=mydata.AZLStat;
                let cfst=mydata.ACFStat;
                let fkst=mydata.AFKStat;
                let zlgzck1=true;
                let zlgzck2=false;
                if(zlgzst>0)
                {
                    zlgzck1=false;
                    zlgzck2=true;
                }
                let cffsck1=true;
                let cffsck2=false;
                let jkhd=true;
                if(cfst>0)
                {
                    cffsck1=false;
                    cffsck2=true;
                    jkhd=false;
                }
                let fkfsck1=true;
                let fkfsck2=false;
                if(fkst>0)
                {
                    fkfsck1=false;
                    fkfsck2=true;
                }
                let afdt=util.formatTime(mydata.AFDate);
                let gzdt="";
                if(mydata.AZLGZDate!=null && mydata.AZLGZDate.length>0)
                {
                    gzdt=mydata.AZLGZDate;
                }
                let fkdt="";
                if(mydata.AFKDate!=null && mydata.AFKDate.length>0)
                {
                    fkdt=mydata.AFKDate;
                }
                ayid=mydata.AYID;
                let myxbbh=mydata.XBRBH;
                var ajimgs=[];
                if(mydata.AJImg!=null && mydata.AJImg.length>0)
                {
                    ajimgs=mydata.AJImg.split(',');
                }
                that.aylist(ayid);
                that.emplist(myxbbh);
                that.setData({
                    ajid:myid,
                    switchck:psck,
                    gzstat:zlgzst,
                    cfstat:cfst,
                    fkstat:fkst,
                    zlck1:zlgzck1,
                    zlck2:zlgzck2,
                    cfck1:cffsck1,
                    cfck2:cffsck2,
                    fkck1:fkfsck1,
                    fkck2:fkfsck2,
                    dsrname:mydata.DSR,
                    dsrhm:mydata.DSRHM,
                    dsrzhuzhi:mydata.DSRAddress,
                    dsrtel:mydata.DSRTel,
                    ayName:mydata.AY,
                    ayid:ayid,
                    afaddress:mydata.AFAddress,
                    hourMinuteSecond:afdt,
                    date:gzdt,
                    jkdate:fkdt,
                    fkxx:mydata.AJCFXX,
                    fkpjh:mydata.AJCFPJH,
                    zbr:mydata.ZBR,
                    zbrid:mydata.ZBRID,
                    zbrbh:mydata.ZBRBH,
                    xbr:mydata.XBR,
                    xbrid:myxbbh,
                    ajstat:mydata.AJStat,
                    imgList:ajimgs,
                    imgurls:ajimgs,
                    jkhide:jkhd,
                    isperson:isp,
                    dsrhmtitle:dsrhm,
                    saomiaohd:true
                })
            }
            
          }
        });
    }
    else
    {
        this.aylist(0);
        this.emplist(0);
    }
    
  },
  aylist(ayid)
  {
      //console.log("ayid"+ayid);
      var that=this;
    wx.request({
        url: constant.host+'/appserv/getaylst.ashx',
        data: {
          cid:constant.cityid,
          k: constant.wkey
        },
        success: function (data) {
          var dat = data.data;
          //console.log(dat);
          var pcname=[];
          var cpkey=[];
          var ayindex=0;
          pcname.push('请选择案由');
          for(var i=0;i<dat.length;i++)
          {
            
            dat[i].id=i;
            dat[i].ayid=dat[i].ayID;
            dat[i].ayName=dat[i].ayName;
            cpkey.push(dat[i]);
            //console.log(dat[i].ayName);
            pcname.push(dat[i].ayName);
            if(dat[i].ayid==ayid)
            {
                ayindex=i;
            }
          }
  
          
          //console.log(orderlist.length);
          that.setData({
            index:ayindex,
            aypickname:pcname,
            aypicker:cpkey
          });
        }
      });
  },
  emplist(embh)
  {
      //console.log(embh);
    var udep=wx.getStorageSync('udept');
      var that=this;
    wx.request({
        url: constant.host+'/appserv/getemplst.ashx',
        data: {
            dep:udep,
          k: constant.wkey
        },
        success: function (data) {
          var dat = data.data;
          var epname=[];
          var epkey=[];
          let myxbindex=0;
          for(var i=0;i<dat.length;i++)
          {
            
            dat[i].id=i;
            dat[i].zfzbh=dat[i].ZFZBH;
            dat[i].Name=dat[i].Name;
            epkey.push(dat[i]);
            //console.log(dat[i].ayName);
            epname.push(dat[i].Name);
            if(dat[i].ZFZBH==embh)
            {
                myxbindex=i;
            }
          }
  
          
          //console.log(orderlist.length);
          that.setData({
            xbindex:myxbindex,
            empnames:epname,
            emps:epkey
          });
        }
      });
  },
  setajstat(e){
    var ckvl=e.detail.value;
    var dstitle='';
    var dshm='';
    var smhd=false;
    var isp=1;
    var cdtype="idCard";
    if(ckvl==true)
    {
        dstitle="当事人";
        dshm="身份证号";
        smhd=false;
        isp=1;
    }
    else
    {
        dstitle="单位名称";
        dshm="统一社会信用代码";
        smhd=true;
        isp=0;
        cdtype="businessLicense";
    }
    this.setData({
        dsrtitle:dstitle,
        dsrhmtitle:dshm,
        smhide:smhd,
        isperson:isp,
        cardtype:cdtype
    })
  },
  
  csaddrzs()
  {
    wx.chooseLocation({
      success:res=>{
          if(res.address!=''&&res.name!='')
          {
              this.setData({
                dsrzhuzhi:res.address
              })
          }
      }
    })
  },
  csaddr()
  {
    wx.chooseLocation({
      success:res=>{
          if(res.address!=''&&res.name!='')
          {
              this.setData({
                afaddress:res.address
              })
          }
      }
    })
  },
  PickerChange(e) {
    //console.log(e.detail.value);
    var ayidx=e.detail.value-1;
    //console.log(ayidx);
    var myayname=this.data.aypicker[ayidx].ayName;
    var myayid=this.data.aypicker[ayidx].ayID;
    //console.log(myayid+'|'+myayname);
    this.setData({
      index: ayidx,
      ayName:myayname,
      ayid:myayid
    })
  },

  XBPickerChange(e) {
    //console.log(e.detail.value);
    var idx=e.detail.value;
    var myxbr=this.data.emps[idx].Name;
    var myxbrbh=this.data.emps[idx].ZFZBH;
    //console.log(myxbr+'|'+myxbrbh);
    this.setData({
      xbindex: e.detail.value,
      xbr:myxbr,
      xbrid:myxbrbh
    })
  },
 
  DateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  JKDateChange(e) {
    this.setData({
      jkdate: e.detail.value
    })
  },
  RegionChange: function(e) {
    this.setData({
      region: e.detail.value
    })
  },
  ChooseImage() {
    wx.chooseImage({
      count: 4, //默认9
      sizeType: ['compressed'],
      //sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], //从相册选择
      success: (res) => {
        
        if (this.data.imgList.length != 0) {
            var that=this;
            wx.uploadFile({
                url: constant.host+'/appserv/upimg.ashx',
                formData: {
                  cid: constant.cityid,
                  k: constant.wkey,
                  p:'/content/jyjzimg/'
                },
                filePath: res.tempFilePaths[0],
                name: 'filename',
                success: function (ress) {
                  //console.log(res.data)
                  var dat=ress.data; 
                  //console.log("a"+dat)
                  if (dat.length > 4) {
                
                    var imgArr = that.data.imgurls;
                   
                    imgArr.push(dat);
                    //console.log(imgArr.join(','));
                    that.setData({
                        imgList: that.data.imgList.concat(res.tempFilePaths),
                        imgurls:imgArr
                    })           
                    
                  }
                  else {
                    wx.showToast({
                      title: '上传失败',
                    })
                  }           
                  wx.hideToast();              
                  
                },
                fail: function(res) {
                    wx.hideToast();
                    wx.showModal({
                        title: '错误提示',
                        content: '上传图片失败',
                        showCancel: false,
                        success: function(res) { }  
                    })
              
                }  
  
              })
          //this.setData({
          //  imgList: this.data.imgList.concat(res.tempFilePaths)
          //})
        } else {
            var that=this;
            wx.uploadFile({
                url: constant.host+'/appserv/upimg.ashx',
                formData: {
                  cid: constant.cityid,
                  k: constant.wkey,
                  p:'/content/jyjzimg/'
                },
                filePath: res.tempFilePaths[0],
                name: 'filename',
                success: function (ress) {
                  //console.log(res.data)
                  var dat=ress.data; 
                  //console.log("b"+dat)
                  if (dat.length > 4) {
                
                    var imgArr = that.data.imgurls;
                   
                    imgArr.push(dat);
                    //console.log(imgArr.join(','));
                    that.setData({
                        imgList: res.tempFilePaths,
                        imgurls:imgArr
                    })           
                    
                  }
                  else {
                    wx.showToast({
                      title: '上传失败',
                    })
                  }           
                  wx.hideToast();              
                  
                },
                fail: function(res) {
                    wx.hideToast();
                    wx.showModal({
                        title: '错误提示',
                        content: '上传图片失败',
                        showCancel: false,
                        success: function(res) { }  
                    })
              
                }  
  
              })
          //this.setData({
          //  imgList: res.tempFilePaths
          //})
        }
      }
    });
  },
  ViewImage(e) {
      //console.log(e.currentTarget.dataset.url)
      var urls=this.data.imgurls;
      var imgpath=this.data.imgpath;
      var imgs=[];
      for(var i=0;i<urls.length;i++)
      {
          var myurl=imgpath+urls[i];
          imgs.push(myurl);
      }

    wx.previewImage({
      urls: imgs,
      current: imgpath+e.currentTarget.dataset.url
    });
  },
  DelImg(e) {
      //console.log(e.currentTarget.dataset.index);
      let delimg=this.data.imgurls[e.currentTarget.dataset.index];
      //console.log(delimg);
    wx.showModal({
      title: '删除',
      content: '确定要删除吗？',
      cancelText: '再看看',
      confirmText: '删除',
      success: res => {
        if (res.confirm) {
            var that=this;
            wx.request({
                url: constant.host+'/appserv/upimgdel.ashx',
                data: {
                  k: constant.wkey,
                  p: '/content/jyjzimg/'+constant.cityid+'/'+delimg
                },
                method: 'GET',
                header: {
                  'Accept': 'application/json'
                },
                success: function (res) {
                  //console.log(res.data)
                  var dat = res.data;
    
                  if (dat==1) {
                    that.data.imgList.splice(e.currentTarget.dataset.index, 1);
                    that.data.imgurls.splice(e.currentTarget.dataset.index, 1);
                    that.setData({
                      imgList: that.data.imgList,
                      imgurls:that.data.imgurls
                    })
                  }
                  else {
                    wx.showToast({
                      title: '删除失败',
                    })
                  }
                  wx.hideToast();
       
    
                },
              })
       
        }
      }
    })
  },
  textareaAInput(e) {
    this.setData({
      textareaAValue: e.detail.value
    })
  },
  textareaBInput(e) {
    this.setData({
      textareaBValue: e.detail.value
    })
  },
  handleSubmit: function (event) {

    var dsrname = event.detail.value.dsrname;
    if (dsrname == '') {
        util.showFailToast({
          title: '输入当事人名称'
        });
  
        return;
      }
    var dsrhm = event.detail.value.dsrhm;
    if (dsrhm == '') {
        util.showFailToast({
          title: '输入当事人证件号'
        });
  
        return;
      }
    var dsrzhuzhi = event.detail.value.dsrzhuzhi;
    if (dsrzhuzhi == '') {
        util.showFailToast({
          title: '输入当事人地址'
        });
  
        return;
      }
    var dsrtel = event.detail.value.dsrtel;
    if (dsrtel == '') {
        util.showFailToast({
          title: '输入当事人电话'
        });
  
        return;
      }
      else
      {
        if (!util.isPhone(dsrtel)) {
            util.showFailToast({
              title: '手机格式不对'
            });
    
            return;
          }
      }

    var ayname = this.data.ayName;
    var ayid = this.data.ayid;
    if (ayid <1) {
        util.showFailToast({
          title: '请选择案由'
        });
  
        return;
      }
    var afdd=event.detail.value.afaddress;
    if (afdd == '') {
        util.showFailToast({
          title: '请输入案发地点'
        });
  
        return;
      }
    var afdt=this.data.hourMinuteSecond;
    if (afdt == '') {
        util.showFailToast({
          title: '请选择案发时间'
        });
  
        return;
      }

    var gzst=this.data.gzstat;
    var gzdes='';
    var gzdt=this.data.date;
    var gzdtc=util.formatTimeToC(gzdt);
    if(gzst>0)
    {
        
        if(gzdt=='')
        {
            util.showFailToast({
                title: '责令改正时间'
              });
        
              return;
        }
        else
        {
            gzdes="于"+gzdtc+"前改正"
        }
        
    }
    else
    {
        gzdes="立即改正";
    }

    var cfst=this.data.cfstat;
    var fk=event.detail.value.fkxx;
    var fkdx='';
    var cfdes='';
    var fkpj='';
    if(cfst>0)
    {
        if(fk=='')
        {
            util.showFailToast({
                title: '请输入罚款金额'
              });
        
              return;
        }
        else
        {
            fkdx=this.changeToChineseMoney(fk);
            cfdes="罚款人民币"+fk+"元，大写"+fkdx;
            fkpj=event.detail.value.fkpjh;
        }
        
    }
    else
    {
        fk=0;
        cfdes="警告";
    }
    var jast=this.data.ajstat;
    if(cfst==0 && jast==0)
    {
        jast=1;
    }
    

    var fkst=this.data.fkstat;
    var fkdes='';
    var jkdt=this.data.jkdate;
    var jkdtc=util.formatDateToC(jkdt);
    if(fkst>0)
    {
        
        if(jkdt=='')
        {
            util.showFailToast({
                title: '选择责交款期限'
              });
        
              return;
        }
        else
        {
            fkdes="要求你（单位）于"+jkdtc+"前将罚款交至"+this.data.khyh+"，账号："+this.data.khyhzh
        }
        jast=1;
    }
    else
    {
        fkdes="当场交款";
    }
    var zbid=this.data.zbrid;
    var zb=this.data.zbr;
    var zbbh=this.data.zbrbh;
    var xb=this.data.xbr;
    var xbbh=this.data.xbrid;

    if (xb == '') {
        util.showFailToast({
          title: '请选择协办人'
        });
  
        return;
      }
      var aid=this.data.ajid;
      var isp=this.data.isperson;
      var bm=this.data.zxbm;
      var im=this.data.jzimg;
  // var formdata=event.detail.value
      var imgs=this.data.imgurls.join(',');
      //console.log(imgs);
    wx.request({
      url: constant.host+'/appserv/jzcreat.ashx',
 
      header:{
        //'Content-type':'application/x-www-form-urlencoded'
        'content-type':'application/x-www-form-urlencoded'
      },
      method: "POST",
      data:util.json2Form({
        id: aid,
        isp: isp,
        zbrid: zbid,
        dsr:dsrname,
        dsrhm:dsrhm,
        dsrzs:dsrzhuzhi,
        dsrtel:dsrtel,
        ay:ayname,
        ayid:ayid,
        afdd:afdd,
        afdt:afdt,
        gz:gzdes,
        cf:cfdes,
        cfxx:fk,
        cfdx:fkdx,
        cfpjh:fkpj,
        cffs:fkdes,
        zbrid:zbid,
        zbr:zb,
        zbrbh:zbbh,
        xbr:xb,
        xbrbh:xbbh,
        dep:bm,
        img:imgs,
        zlst:gzst,
        cfst:cfst,
        fkst:fkst,
        gzdt:gzdt,
        fkdt:jkdt,
        ajst:jast,
        k:constant.wkey
        //formdata
      }), 
    
      success: function (res) {
          //console.log("r:"+res.data);
          if(res.data>0)
          {
     
            wx.showToast({
              title: "操作成功",
              icon: 'success',
              mask: true,
              duration: 20000,
              success: function (ress) {
               
                  wx.redirectTo({
                    url: 'anjianedit?id='+res.data,
                  })
              }

            });
            
      
          }
          else
          {
            util.showFailToast(
              {
                title: "操作失败，请重试"
              }
            )
          }
        
      },
      fail:function(res)
      {
        console.log(res.data)
        util.showFailToast({
          title: "操作失败！请重试"
        });
      }
    });
  },
  dojiean()
  {
      var aid=this.data.ajid;
      wx.showModal({
        title: '结案',
        content: '结案后所有信息将不可修改，确定要结案吗？',
        cancelText: '再看看',
        confirmText: '结案',
        success: res => {
          if (res.confirm) {
            var that=this;
            wx.request({
              url: constant.host+'/appserv/jiean.ashx',
         
              header:{
                //'Content-type':'application/x-www-form-urlencoded'
                'content-type':'application/x-www-form-urlencoded'
              },
              method: "POST",
              data:util.json2Form({
                id: aid,
                k:constant.wkey
                //formdata
              }), 
            
              success: function (res) {
                  //console.log("r:"+res.data);
                  if(res.data>0)
                  {
             
                    wx.showToast({
                      title: "操作成功",
                      icon: 'success',
                      mask: true,
                      duration: 2000,
                      success: function (ress) {
                        that.setData({
                            ajstat:2
                        })
                    
                      }
        
                    });
                    
              
                  }
                  else
                  {
                    util.showFailToast(
                      {
                        title: "操作失败，请重试"
                      }
                    )
                  }
                
              },
              fail:function(res)
              {
                console.log(res.data)
                util.showFailToast({
                  title: "操作失败！请重试"
                });
              }
            });
          }
        }
      })
      
  },
  printview(){
    var aid=this.data.ajid;
    wx.navigateTo({
      url: 'printview?aid='+aid,
    })
  },
  zgview(){
    var aid=this.data.ajid;
    wx.navigateTo({
      url: 'zgview?aid='+aid,
    })
  }
})